import sqlite3

def createTables():
	conn = sqlite3.connect("db")
	c = conn.cursor()

	c.execute('''
		CREATE TABLE users(
		id INTEGER PRIMARY KEY DEFAULT NULL
		,name TEXT
		,password TEXT)
		''')

	c.execute('''
		CREATE TABLE threads(
		id INTEGER PRIMARY KEY DEFAULT NULL
		,title TEXT
		,created DATETIME DEFAULT CURRENT_TIMESTAMP
		,last_post DATETIME
		,created_by INTEGER
		,FOREIGN KEY(created_by) REFERENCES users(id))
		''')

	c.execute('''
		CREATE TABLE posts(
		id INTEGER PRIMARY KEY DEFAULT NULL
		,thread_id INTEGER
		,message TEXT
		,created_by INTEGER
		,created DATETIME DEFAULT CURRENT_TIMESTAMP
		,FOREIGN KEY (created_by) REFERENCES users(id)
		,FOREIGN KEY (thread_id) REFERENCES threads(id))
		''')

	conn.commit()


if __name__ == "__main__":
	c.execute('''insert into users (name,password) values ('test','test')''')
	conn.commit()
	c.execute('''select * from users''')
	for i in c:
		print i
	
	c.execute('''insert into threads (title,last_post,created_by) values ('title',CURRENT_TIMESTAMP,1)''')
	conn.commit()
	c.execute('''select * from threads''')
	for i in c:
		print i
	
	c.execute('''insert into posts (thread_id,message,created_by) values (1,'lol hi!',1)''')
	conn.commit()
	c.execute('''select * from posts''')
	for i in c:
		print i